#include "brightness.h"


struct input_event ev_data;

Brightness::Brightness(QWidget *parent) : QWidget(parent)
{
    bh1726_fd = -1;

    bh1726_init();
}

Brightness::~Brightness()
{

}


int Brightness::bh1726_init(void)
{
    ::system("echo 1 > /sys/bus/i2c/devices/1-0029/enable_als_sensor");

    if((bh1726_fd = open(ALS_DEV, O_RDONLY)) < 0)
    {
        printf("Error open %s\n\n", ALS_DEV);
        return -1;
    }

    return bh1726_fd;
}

void Brightness::bh1726_read(int *data)
{
    read(bh1726_fd, &ev_data, sizeof(ev_data));

    if (ev_data.type == EV_ABS)
    {
        //printf(" ev_data.type = %d,ev_data.code = %d, ev_data.value = %d\n\n",ev_data.type,ev_data.code, ev_data.value);
        if(ev_data.value)
            *data = ev_data.value;
    }
}
